#include "internal.h"

/*
 * When switching a task to RT, we may overload the runqueue
 * with RT tasks. In this case we try to push them off to
 * other runqueues.
 */
static void switched_to_rt(struct rq *rq, struct task_struct *p)
{
    /*
     * If we are running, update the avg_rt tracking, as the running time
     * will now on be accounted into the latter.
     */
    if (task_current(rq, p))
    {
        update_rt_rq_load_avg(rq_clock_pelt(rq), rq, 0);
        return;
    }

    /*
     * If we are not running we may need to preempt the current
     * running task. If that current running task is also an RT task
     * then see if we can move to another run queue.
     */
    if (task_on_rq_queued(p))
    {
        if (p->nr_cpus_allowed > 1 && rq->rt.overloaded)
            rt_queue_push_tasks(rq);
        if (p->prio < rq->donor->prio && cpu_online(cpu_of(rq)))
            resched_curr(rq);
    }
}
